﻿using System.Linq;
using System.Web.Mvc;
using System.Data.Entity;
using VOD.Models;

namespace VOD.Controllers
{
    public class RankController : Controller
    {
        VODEntities db = new VODEntities();
        // 排行榜首页 显示所有排行
        // GET: /Rank/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Movie()
        {
            return View();
        }

        /// <summary>
        /// 电影栏目Top10 
        /// </summary>
        /// <param name="id">类别TypeID</param>
        /// <returns></returns>
        public ActionResult MovieTop10(int id)
        {
            var videos = db.Videos
                .Include(v => v.VideoAndTypes.Select(t => t.VideoType))
                .Include(v=>v.PlayRecords)
                .Where(v => v.CategoryID == 2)
                .OrderByDescending(v=>v.PlayRecords.Count)
                .Select(v=>v);
            if (id > 1)
            {

            }
            return View();
        }

        /// <summary>
        /// Top10 排行榜
        /// </summary>
        /// <param name="id">分类CategoryID</param>
        /// <param name="typeID"> </param>
        /// <param name="topTitle"> </param>
        /// <returns></returns>
        public ActionResult Top10(int? id,int? typeID,string topTitle)
        {
            var videos = db.Videos.Include(v=>v.PlayRecords).OrderByDescending(v=>v.PlayRecords.Count).Select(v=>v);
            if (id>1)
            {
                videos = videos.Where(v => v.CategoryID == id);
            }
            //ViewBag.TopTitle = topTitle;
            switch (id)
            {
                case 2:
                    ViewBag.TopTitle = "电影";
                    break;
                case 3:
                    ViewBag.TopTitle = "电视剧";
                    break;
                case 4:
                    ViewBag.TopTitle = "动漫";
                    break;
                case 5:
                    ViewBag.TopTitle = "综艺";
                    break;
                case 6:
                    ViewBag.TopTitle = "教程";
                    break;
                default:
                    ViewBag.TopTitle = "全部";
                    break;
            }
            if (typeID != null)
            {
                videos = videos.Where(v => v.VideoAndTypes.Any(t => t.TypeID == typeID));
                ViewBag.TopTitle = db.VideoTypes.Find(typeID).TypeName;
            }
            return View(videos.Take(10).ToList());
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
